package demo;

import junit.framework.Assert;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
import org.springframework.transaction.annotation.Transactional;

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
DependencyInjectionTestExecutionListener.class,
TransactionalTestExecutionListener.class})
@Transactional
@ContextConfiguration(
locations={"classpath:modelApplicationContext.xml"})
public class SpringTestingDemo {
    
    @Autowired
    private MemberService memberService;

    @Test
    @Rollback(value=true)
    public void memberTest() {
        Member member = new Member();
        member.setName("blah");
        memberService.saveOrUpdate(member, "creating");
        member.setName("joe");
        memberService.saveOrUpdate(member, "changing name");
        Assert.assertEquals(2, memberService.findNotesByMember(member).size());
        Assert.assertEquals(2, memberService.findNotesByMember(member).size());
    }
}
